<template>
    <form-item 
        :designer="designer" 
        :field="field"
        >
        <el-button 
            :disabled="disabled" 
            :size="size"
        >
            {{ state.fieldVal }}
        </el-button>
    </form-item>
</template>

<script setup>
import { reactive,onMounted,nextTick, computed } from 'vue';
import FormItem from './form-item.vue';
defineOptions({
    name:"xy-button"
})
const props = defineProps({
    designer:{
        type:Object,
        default:()=>({})
    },
    field:{
        type:Object,
        default:()=>({})
    },
    formModel:{
        type:Object,
        default:()=>({})
    }
})

const state = reactive(({
    fieldVal:"按钮",
}))

const setFieldVal = val=>{
    props.formModel[props.field.options.name] = val
}

const size = computed(()=>{
    return props.field.options.size || 'default'
})

const disabled = computed(()=>{
    return props.field.options.disabled
})

onMounted(()=>{
    if(props.field && props.field.options.defaultValue){
        // 存在默认值的情况下进行初始化
        setFieldVal(props.field.options.defaultValue)
    }

    nextTick(()=>{
        if(!props.designer) return
        props.designer.createFieldValFun(props.field.id, setFieldVal)
    })
})
</script>

<style lang="scss" scoped>
:deep(.el-form-item)    {
    .el-form-item__label{
        overflow: hidden!important;
        width: 0!important;
    }
}
</style>
